export default function useRepaymentHistory(arr: any[]=[]) {
  if(arr.length === 0) return []
 const result: any[][] = []
const sort:any = {}
let initialIndex = -1
function getIndex(year){
  if(sort.hasOwnProperty([year])){
    return sort[year]
  }else{
    sort[year] = ++initialIndex
    return sort[year]
  }
}

    for(var i = 0; i< arr.length; i++){
      const item = arr[i]
      const [year, month] = item.PD01ER03.split('.')
      
      const index = getIndex(year)
      if(!Array.isArray(result[index])){
        result[index] = generateMonthArr(year)
      }
      
      result[index][Number(month)] = {
        PD01ED01: item.PD01ED01,
        PD01EJ01: item.PD01EJ01
      }
    }
    function generateMonthArr(year: string): any[]{
      const arr:any[] = []
      for (let index = 0; index < 13; index++) {
        arr.push(index==0?year: {})
      }
      return arr
    }
  return result.sort((a,b) =>  b[0] - a[0])
}